#include <vtkline.h>
#include <vtkNew.h>
#include<vtkPoints.h>
#include <iostream>
#include <string>

int main(int argc, char *argv[])
{
    //定义两个点用于确定一条线
    double lineP0[3] = {0.0, 0.0, 0.0};
    double lineP1[3] = {2.0, 0.0, 0.0};

    //计算这两个点到线之间的距离
    double P0[3] = {1.0, 0, 0};
    double P1[3] = {1.0, 2.0, 0};

    //vtkNew是vtk中的智能指针
    vtkNew<vtkLine> line;

    //使用SetPoint方法来进行设置线段的两个端点的值
    line->GetPoints()->SetPoint(0, lineP0);
    line->GetPoints()->SetPoint(1, lineP1);

    {
        double dist0 = vtkLine::DistanceToLine(P0, lineP0, lineP1);
        std::cout << "Dist0:" << dist0 << std::endl;
        double dist1 = vtkLine::DistanceToLine(P1, lineP0, lineP1);
        std::cout << "Dist1:" << dist1 << std::endl;
    }

    {
        double t;
        double closest[3];
        double dist0 = vtkLine::DistanceToLine(P0, lineP0, lineP1, t, closest);
        std::cout << "Dist0: " << dist0 << " closest point: " << closest[0] << " "
                  << closest[1] << " " << closest[2] << std::endl;

        double dist1 = vtkLine::DistanceToLine(P1, lineP0, lineP1, t, closest);
        std::cout << "Dist1: " << dist1 << " closest point: " << closest[0] << " "
                  << closest[1] << " " << closest[2] << std::endl;
    }
    return EXIT_SUCCESS;
}
